package com.zklh.leetcode.other;

import java.util.Arrays;
import java.util.List;

/**
 * 按位与最大的最长子数组
 *
 * @author tongnan
 * @date 2024/12/23
 */
public class Solution2419 {
    public int longestSubarray(int[] nums) {
        int maxValue = nums[0];
        int maxLength = 1;
        int current = 1;
        int currentLength = 1;
        boolean isContinuous = true;

        while (current < nums.length) {
            if (isContinuous && nums[current] == maxValue) {
                currentLength += 1;
                if (currentLength > maxLength) {
                    maxLength = currentLength;
                }
            } else if (nums[current] == maxValue) {
                currentLength = 1;
                isContinuous = true;
            } else if (nums[current] > maxValue) {
                currentLength = 1;
                maxValue = 1;
                isContinuous = true;
            } else if (nums[current] < maxValue) {
                isContinuous = false;
                currentLength = 0;
            }
            current++;
        }

        return maxLength;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{323376, 323376, 323376, 323376, 323376, 323376, 323376, 75940, 323376, 323377, 323377};
        Solution2419 solution = new Solution2419();
        System.out.println(solution.longestSubarray(nums));
    }
}
